package com.sport.mapper;

import com.sport.pojo.dto.Referee;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.time.LocalDateTime;

@Mapper
public interface JudgeMapper {

    @Insert("insert into uandr (room_id,user_id,camp)values (#{roomId},#{userId},2)")
    int addJudgeInUR(Referee referee);
    @Update("update room set current_count = current_count + 1 where room_id = #{roomId}")
    int addNum(Referee referee);
    @Select("select count(*) from uandr where room_id=#{roomId} and camp=2")
    int isJudge(Referee referee);
    @Update("update room set begin_time = #{now},room_status = 2 where room_id = #{roomId}")
    int start( LocalDateTime now,String roomId);
    @Update("update room set end_time = #{now},outcome = #{outCome},outcome_num=#{outComeNum},room_status = 3 where room_id = #{roomId}")
    int updateEndGame(LocalDateTime now,String roomId,int outCome, String outComeNum);
    @Update("update user as a join uandr as  u on a.user_id = u.user_id set a.user_football_dan = case when u.camp = #{camp} then a.user_football_dan -5\n" +
            "    else a.user_football_dan + 5\n" +
            "    end\n" +
            "where room_id=#{roomId};")
    int changeDao(int camp,String roomId);

    @Update("update user as a join uandr as u on a.user_id = u.user_id set a.user_football_dan = a.user_football_dan+5 where u.camp = 2 and room_id=#{roomId};")
    int draw(String roomId);
}
